<?php
/**
 * The Template for displaying all single posts.
 *
 * @package WordPress
 * @subpackage Sastro
 * @since Sastro 1.0
 */

get_header(); 

$initial = THE_INITIAL;
?>

        <div id="singlepost">
        
             <?php if ( have_posts() ) while ( have_posts() ) : the_post(); ?>
             <article id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
				<?php
                 
				$custom = get_post_custom($post->ID);
				$_post_format = get_post_format();
				switch ($_post_format) {
					case "video":
						
						$cf_vidurl = (isset($custom["_".$initial."_video_url"][0]))? $custom["_".$initial."_video_url"][0] : "";
						if($cf_vidurl!=''){
							echo '<div class="mediacontainer">'.apply_filters('the_content', $cf_vidurl)."</div>";
						}
						$iconclass = "fa-film";
						
					break;
					case "audio":
					
						$cf_audurl = (isset($custom["_".$initial."_audio_url"][0]))? $custom["_".$initial."_audio_url"][0] : "";
						if($cf_audurl!=''){
							echo '<div class="mediacontainer">'.apply_filters('the_content', $cf_audurl)."</div>";
						}
						$iconclass = "fa-volume-up";
					
					break;
					case "gallery":
						
						$post_content = get_the_content();
						preg_match('/\[gallery.*ids=.(.*).\]/', $post_content, $ids);
						$array_id = explode(",", $ids[1]);
						
						$content =  str_replace($ids[0], "", $post_content);
						$filtered_content = apply_filters( 'the_content', $content);
						
						$sliderli = '';
						foreach($array_id as $img_id){
							$sliderli .= '<li><a href="'. get_permalink() .'">'. wp_get_attachment_image( $img_id, 'blog-post-image' ) .'</a></li>';
						}
						
						if($sliderli!=''){
							echo '<div class="gallerycontainer"><div class="flexslider"><ul class="slides">'.$sliderli."</ul></div></div>";
						}
						$iconclass = "fa-image";
						
					break;
					case "image":
						
						$cf_imgurl = (isset($custom["image_url"][0]))? $custom["image_url"][0] : "";
						$imgurl = "";
						/* temporary not used */
						if($cf_imgurl!=""){
							$imgurl = '<img src='. $cf_imgurl .' alt="'. get_the_title( $post->ID ).'" class="scale-with-grid"/>';
						}elseif(has_post_thumbnail($post->ID) ){
							$imgurl = get_the_post_thumbnail($post->ID, 'blog-post-image', array('class' => 'scale-with-grid'));
						}else{
							$imgurl ="";
						}
						
						if($imgurl!=''){
							echo '<div class="imgcontainer">'.$imgurl."</div>";
						}
						$iconclass = "fa-camera";
						
					break;
					
					default :
						$iconclass = "fa-file-text-o";
					
					break;
				}
				?>
                <h2 class="posttitle"><a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', THE_LANG ), the_title_attribute( 'echo=0' ) ); ?>" data-rel="bookmark"><?php the_title(); ?></a></h2>
                <div class="entry-utility">
                    <span class="meta-author"><?php _e('By', THE_LANG); ?> <a href="<?php echo get_author_posts_url( get_the_author_meta( 'ID' ) );?>"><?php the_author();?></a></span> &nbsp;&nbsp;/&nbsp;&nbsp;
                    <span class="meta-date"><i class="fa fa-calendar"></i>&nbsp; <?php the_time('M d, Y') ?></span>&nbsp;&nbsp;/&nbsp;&nbsp;
                    <span class="meta-cat"><i class="fa fa-folder-open"></i>&nbsp; <?php the_category(', '); ?></span>&nbsp;&nbsp;/&nbsp;&nbsp;
                    <span class="meta-tag"><?php the_tags('<i class="fa fa-tags"></i>&nbsp;&nbsp;'); ?></span>
                    <div class="clearfix"></div>
                </div>
                
                <div class="entry-icon"><div class="fa <?php echo $iconclass; ?>"></div></div>
                
                 <div class="entry-content">
                    <?php 
					if(isset($filtered_content)){
						echo do_shortcode($filtered_content);
					}else{
						the_content();
					}
					?>
                    <?php wp_link_pages( array( 'before' => '<div class="page-link"><span>' . __( 'Pages:', THE_LANG ) . '</span>', 'after' => '</div>' ) ); ?>
                    <div class="clearfix"></div>
                    <?php do_action('nvr_share_button'); ?>
                    <div class="clearfix"></div>
                </div>
                
             </article>
            <?php
            
            // If a user has filled out their description, show a bio on their entries.
            if ( get_the_author_meta( 'description' ) ) : ?>
            <div id="entry-author-info">
                <div id="author-avatar">
                    <?php echo get_avatar( get_the_author_meta( 'user_email' ), apply_filters( 'novaro_author_bio_avatar_size', 111 ) ); ?>
                </div><!-- author-avatar -->
                <div id="author-description">
                    <h2><span class="author"><?php printf( __( 'About %s', THE_LANG ), get_the_author() ); ?></span></h2>
                    <?php the_author_meta( 'description' ); ?>
                </div><!-- author-description	-->
            </div><!-- entry-author-info -->
            <?php endif; ?>
            
            <div id="prevnext-post-link">
            	<?php
				$nextpost = get_next_post(true);
				$prevpost = get_previous_post(true);
                if(!empty($prevpost)){
					if(has_post_thumbnail($prevpost->ID)){
						$imgurl = get_the_post_thumbnail($prevpost->ID, 'thumbnail', array('class' => 'prevthumb'));
                	}else{
						$imgurl = '';
					}
					echo '<div class="nav-previous"><a href="'.get_permalink($prevpost->ID).'">'.$imgurl.'<span class="navtext">'. __( 'Previous Article', THE_LANG ) .'</span><br /><span class="prevnexttitle">'.get_the_title($prevpost->ID).'</span></a></div>';
                }
				if(!empty($nextpost)){
					if(has_post_thumbnail($nextpost->ID)){
            			$imgurl = get_the_post_thumbnail($nextpost->ID, 'thumbnail', array('class' => 'nextthumb'));
					}else{
						$imgurl = '';
					}
					echo '<div class="nav-next"><a href="'.get_permalink($nextpost->ID).'">'.$imgurl.'<span class="navtext">'. __( 'Next Article', THE_LANG ) .'</span><br /><span class="prevnexttitle">'.get_the_title($nextpost->ID).'</span></a></div>';
                }
                ?>
                <div class="clearfix"></div>
            </div>
            
            <?php comments_template( '', true ); ?>
            
            <?php endwhile; ?>
        
        </div><!-- singlepost --> 
                   
<?php get_footer(); ?>